package Control;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import Entity.MsgPackage;
import GUI.EstimationStageGui;
import GUI.ScreenManager;
import Entity.EstimationReport;

/**
 * Controls the instance of Estimation Stage Control
 * This class sends and gets data from the server 
 * and display it on the panel.
 * @author Elad
 */
public class EstimationStageControl {
	private EstimationStageGui estimationGui;
	private MsgPackage estimationMsg;
	private EstimationReport estimationReport;
	
	/**
	 * the constructor
	 */
	public  EstimationStageControl(){
		estimationGui= new  EstimationStageGui();
		estimationMsg= new MsgPackage();
		estimationReport= new EstimationReport(); 
	}
	
	/**
	 * 
	 * @return EstimationStageGui
	 */
	public EstimationStageGui getEstimationGui(){
		return estimationGui;
	}
	
	/**
	 * set the request number in the estimationReport
	 * @param Req
	 */
	public void reqANDstageEntered(String Req){
		estimationReport.setR_id(Integer.parseInt(Req));			
	}
	
	/**
	 * This method sends request to the server
	 *  The server sends an answer (received from query from database) 
	 *  and the control display it in a message
	 */
	public void estimation_Submit_pressed(){
		String a=estimationGui.getTextArea_InfoSystem().getText();
		String b= estimationGui.getTextArea_ReqChange().getText();
		String c= estimationGui.getTextArea_Profit().getText();
		String d= estimationGui.getTextArea_Cons().getText();
		String e= estimationGui.getTextArea_Haz().getText();
		String f= estimationGui.getTextArea_Dur().getText();
		
		if( a==null||b==null||c==null||d==null||e==null||f==null){
			JOptionPane.showMessageDialog(null, "Not all the fileds all the fill", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
		
		else{
			estimationReport.setSystemInformation(estimationGui.getTextArea_InfoSystem().getText());
			estimationReport.setChangeRequired(estimationGui.getTextArea_ReqChange().getText());
			estimationReport.setBenefit(estimationGui.getTextArea_Profit().getText());
			estimationReport.setConstraints(estimationGui.getTextArea_Cons().getText());
			estimationReport.setRisks(estimationGui.getTextArea_Haz().getText());
			estimationReport.setDurationEstimation(Integer.parseInt(estimationGui.getTextArea_Dur().getText()));
			
			estimationMsg.setObject(estimationReport);
			estimationMsg.setOp_code(OP_CODE.ESTIMATION_STAGE);
			ScreenManager.getConnection().accept(estimationMsg);
			JOptionPane.showMessageDialog(null, "Your stage was updated successfully!!", "", JOptionPane.INFORMATION_MESSAGE);
		}
	}
}
			
